package cn.com.api.controller;

import java.io.PrintWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.api.entity.ApiT_shops_apply;

import cn.com.api.service.ApiT_shops_applyService;
import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "t_shops_apply/")
public class ApiT_shops_applyController {
    @Autowired
    private ApiT_shops_applyService apiT_shops_applyService;
	
	private static Logger logger = Logger.getLogger(ApiT_shops_applyController.class);
	
	/**
	 * 新增
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "insertT_shops_apply")
	public void insertT_shops_apply(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		String shop_id = request.getParameter("shop_id");
		String shop_name = request.getParameter("shop_name");
		String shop_type = request.getParameter("shop_type");
		String day_avg_money = request.getParameter("day_avg_money");
		String sign_time = request.getParameter("sign_time");
		String create_time = request.getParameter("create_time");
		String money = request.getParameter("money");
		String bd_user = request.getParameter("bd_user");
		String status = request.getParameter("status");
		String remark = request.getParameter("remark");
        
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			/*
			if(c_uid!=null && !"".equals(c_uid.trim())){
				ApiT_shops_apply t_shops_apply = new ApiT_shops_apply();
				
    		    t_shops_apply.setId(id);
    		    t_shops_apply.setShop_id(shop_id);
    		    t_shops_apply.setShop_name(shop_name);
    		    t_shops_apply.setShop_type(shop_type);
    		    t_shops_apply.setDay_avg_money(day_avg_money);
    		    t_shops_apply.setSign_time(sign_time);
    		    t_shops_apply.setCreate_time(create_time);
    		    t_shops_apply.setMoney(money);
    		    t_shops_apply.setBd_user(bd_user);
    		    t_shops_apply.setStatus(status);
    		    t_shops_apply.setRemark(remark);
				
				apiT_shops_applyService.insertT_shops_apply(t_shops_apply);
				// return
                map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "添加成功！");
			}
			*/
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}

	/**
	 * 根据id查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/findT_shops_applyById")
	public void findT_shops_applyById(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		Map<String,Object> map = new HashMap<String,Object>();
		try{
		    String id = request.getParameter("id");
		    ApiT_shops_apply t_shops_apply = apiT_shops_applyService.findT_shops_applyById(Integer.valueOf(id));
		
			// return
            map.put("datas", t_shops_apply);
            map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
        
	}
	
     /**
	 * 查询数据集
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/findT_shops_applys")
	public void findT_shops_applys(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		Map<String,Object> map = new HashMap<String,Object>();
		try{
		    List<ApiT_shops_apply> t_shops_applys = apiT_shops_applyService.findT_shops_applys();
		
			// return
            map.put("datas", t_shops_applys);
            map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "查询成功！");
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
        
	}
	
    
	/**
	 * 修改
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@Transactional
	@RequestMapping(value = "updateT_shops_apply")
	public void updateT_shops_apply(HttpServletRequest request, HttpServletResponse response) throws Exception {
	
		String shop_id = request.getParameter("shop_id");
		String shop_name = request.getParameter("shop_name");
		String shop_type = request.getParameter("shop_type");
		String day_avg_money = request.getParameter("day_avg_money");
		String sign_time = request.getParameter("sign_time");
		String create_time = request.getParameter("create_time");
		String money = request.getParameter("money");
		String bd_user = request.getParameter("bd_user");
		String status = request.getParameter("status");
		String remark = request.getParameter("remark");
        
        
		String id = request.getParameter("id");
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			if(id!=null && !"".equals(id.trim())){
				ApiT_shops_apply t_shops_apply = new ApiT_shops_apply();
				//获取原数据
				t_shops_apply  = apiT_shops_applyService.findT_shops_applyById(Integer.valueOf(id));
				//修改
				//t_shops_apply.setIs_open(Integer.valueOf(is_open));
				//
				int ret_i = apiT_shops_applyService.updateT_shops_apply(t_shops_apply);
				
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "编辑成功！");
			}else{
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "检查失败！");
			}
		}
		catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}
    
	/**
	 * 删除
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value = "deleteT_shops_apply")
	public void deleteT_shops_apply(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
        String id = request.getParameter("id");
		Map<String,Object> map = new HashMap<String,Object>();
		
		try{
			if(id!=null && !"".equals(id.trim())){
	
				Integer ret_I = apiT_shops_applyService.deleteT_shops_apply(Integer.parseInt(id));
				if(ret_I >0 ){
    				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
    				map.put(Utils.MESSAGE, "删除成功！");
                }else{
				    map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				    map.put(Utils.MESSAGE, "检查失败！");
			    }
			}
		}catch(Exception e){
			logger.error(e);
            e.printStackTrace();  
    		map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
    		map.put(Utils.MESSAGE, "系统异常！");
		}

		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		out.print(JsonUtil.object2json(map));
		out.close();
	}
	
 
}


